home *** CD-ROM | disk | FTP | other *** search
/ Amiga Games Extra 1996 September / Amiga Games Extra CD-ROM 9-1996.iso / userbox / publicdomain / vim-4.2 / doc / vim_tips.txt < prev    next >
Text File  |  1996-06-16  |  11KB  |  308 lines

  1. *vim_tips.txt*  For Vim version 4.2.  Last modification: 1996 June 16
  2.  
  3. Contents:
  4.  
  5. Editing C programs                    |C-editing|
  6. Editing local HTML files (WWW)                |html-editing|
  7. Editing paragraphs without a line break            |edit-no-break|
  8. Switching screens in an xterm                |xterm-screens|
  9. Scrolling in Insert mode                |scroll-insert|
  10. Smooth scrolling                    |scroll-smooth|
  11. Correcting common typing mistakes            |type-mistakes|
  12. Renaming files                        |rename-files|
  13. Speeding up external commands                |speed-up|
  14. Useful mappings                        |useful-mappings|
  15. Compressing the help files                |gzip-helpfile|
  16. Executing shell commands in a window            |shell_window|
  17. Pseudo-Ex mode                        |pseudo-Q|
  18.  
  19.  
  20. Editing C programs                    *C-editing*
  21. ==================
  22.  
  23. There are quite a few features in Vim to help you edit C program files.  Here
  24. is an overview with tags to jump to:
  25.  
  26. |C_indenting|        Automatically set the indent of line while typing
  27.             text.
  28. |=|            Re-indent a few lines.
  29. |format_comments|    Format comments.
  30.  
  31. |:checkpath|        Show all recursively included files.
  32. |[i|            Search for identifier under cursor in current and
  33.             included files.
  34. |[_CTRL-I|        Jump to match for "[i"
  35. |[I|            List all lines in current and included files where
  36.             identifier under the cursor matches.
  37. |[d|            Search for define under cursor in current and included
  38.             files.
  39.  
  40. |CTRL-]|        Jump to tag under cursor.
  41. |CTRL-T|        Jump back from tag.
  42.  
  43. |gd|            Go to Declaration of local variable under cursor.
  44. |gD|            Go to Declaration of global variable under cursor.
  45.  
  46. |gf|            Go to file name under the cursor.
  47.  
  48. |%|            Go to matching (), {}, [], /* */, #if, #else, #endif.
  49. |[/|            Go to previous start of comment.
  50. |]/|            Go to next end of comment.
  51. |[#|            Go back to unclosed #if, #ifdef, or #else.
  52. |]#|            Go forward to unclosed #else or #endif.
  53. |[(|            Go back to unclosed '('
  54. |])|            Go forward to unclosed ')'
  55. |[{|            Go back to unclosed '{'
  56. |]}|            Go forward to unclosed '}'
  57.  
  58. |v_S|            Select current block from "[(" to "])"
  59. |v_P|            Select current block from "[{" to "]}"
  60.  
  61.  
  62. Editing local HTML files (WWW)                *html-editing*
  63. ==============================
  64.  
  65. Vim has some features which can help simplify the creation and maintenance of
  66. HTML files, provided that the files you are editing are available on the local
  67. file system.  The "]f", "gf" and "CTRL-W f" commands can be used to jump to
  68. the file whose name appears under the cursor, thus not only checking that the
  69. link is valid (at least the file name part of the URL) but also providing a
  70. quick and easy way to edit many related HTML pages at once.  |gf|
  71. A set of macros to help with editing html can be found on the Vim pages. |www|
  72.  
  73.  
  74. Editing paragraphs without a line break            *edit-no-break*
  75. =======================================
  76.  
  77. If you are typing text in Vim that will later go to a word processor, it is
  78. useful to keep a paragraph as a single line.  To make this more easy:
  79. - set 'wrap' on, to make lines wrap                |'wrap'|
  80. - set 'linebreak' on, to make wrapping happen at a blank    |'linebreak'|
  81. - use "gk" and "gj" to move one screen line up or down        |gj|
  82.  
  83.  
  84. Switching screens in an xterm                *xterm-screens*
  85. =============================
  86.  
  87. (From comp.editors, by Juergen Weigert, in reply to a question)
  88.  
  89. >> Another question is that after exiting vim, the screen is left as it
  90. >> was, i.e. the contents of the file I was viewing (editting) was left on
  91. >> the screen. The output from my previous like "ls" were lost,
  92. >> ie. no longer in the scrolling buffer. I know that there is a way to
  93. >> restore the screen after exiting vim or other vi like editors,
  94. >> I just don't know how. Helps are appreciated. Thanks.
  95.  
  96. >I imagine someone else can answer this.  I assume though that vim and vi do
  97. >the same thing as each other for a given xterm setup.
  98.  
  99. They not necessarily do the same thing, as this may be a termcap vs.
  100. terminfo problem. You should be aware that there are two databases for
  101. describing attributes of a particular type of terminal: termcap and
  102. terminfo. This can cause differences when the entries differ *and* when of
  103. the programs in question one uses terminfo and the other uses termcap.
  104.  
  105. In your particular problem, you are looking for the control sequences
  106. ^[[?47h and ^[[?47l. These switch between xterms alternate and main screen
  107. buffer. As a quick workaround a command sequence like
  108.     echo -n "^[[?47h"; vim ... ; echo -n "^[[?47l"
  109. may do what you want. (My notation ^[ means the ESC character, further down
  110. you'll see that the databases use \E instead).
  111.  
  112. On startup, vim echoes the value of the termcap variable ti (terminfo:
  113. smcup) to the terminal. When exiting, it echoes te (terminfo: rmcup). Thus
  114. these two variables are the correct place where the above mentioned control
  115. sequences should go.
  116.  
  117. Compare your xterm termcap entry (found in /etc/termcap) with your xterm
  118. terminfo entry (retrieved with /usr/5bin/infocmp -C xterm). Both should
  119. contain entries similar to:
  120.     :te=\E[2J\E[?47l\E8:ti=\E7\E[?47h:
  121.  
  122. PS: If you find any difference, someone (your sysadmin?) should better check
  123.     the complete termcap and terminfo database for consistency.
  124.  
  125. NOTE: If you recompile Vim with SAVE_XTERM_SCREEN defined in feature.h, the
  126. builtin xterm will include the mentioned "te" and "ti" entries.
  127.  
  128.  
  129. Scrolling in Insert mode                *scroll-insert*
  130. ========================
  131.  
  132. If you are in insert mode and you want to see something that is just off the
  133. screen, you can use CTRL-X CTRL-E and CTRL-X CTRL-Y to scroll the screen.
  134.                         |i_CTRL-X_CTRL-E|
  135.  
  136. To make this easier, you could use these mappings:
  137.     :inoremap ^E ^X^E
  138.     :inoremap ^Y ^X^Y
  139. (Type CTRL-V CTRL-E to enter ^E, CTRL-V CTRL-X to enter ^X, etc.)
  140.  
  141. Also consider setting 'scrolloff' to a larger value, so that you can always see
  142. some context around the cursor.  If 'scrolloff' is bigger than half the window
  143. height, the cursor will always be in the middle and the text is scrolled when
  144. the cursor is moved up/down.
  145.  
  146.  
  147. Smooth scrolling                    *scroll-smooth*
  148. ================
  149.  
  150. If you like the scrolling to go a bit smoother, you can use these mappings:
  151.     :map ^U ^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y^Y
  152.     :map ^D ^E^E^E^E^E^E^E^E^E^E^E^E^E^E^E^E
  153.  
  154. (Type CTRL-V CTRL-U to enter ^U, CTRL-V CTRL-Y to enter ^Y, etc.)
  155.  
  156.  
  157. Correcting common typing mistakes            *type-mistakes*
  158. =================================
  159.  
  160. When there are a few words that you keep on typing in the wrong way, make
  161. abbreviations that correct them.  For example:
  162.     :ab teh the
  163.     :ab fro for
  164.  
  165.  
  166. Renaming files                        *rename-files*
  167. ==============
  168.  
  169. Say I have a directory with the following files in them (directory picked at
  170. random :-):
  171.  
  172. addcr.c
  173. alloc.c
  174. amiga.c
  175. ...
  176.  
  177. and I want to rename *.c *.bla.  I'd do it like this:
  178.  
  179. $ vim
  180. :r! ls *.c
  181. :%s/\(.*\).c/mv & \1.bla
  182. :w !sh
  183. :q!
  184.  
  185.  
  186. Speeding up external commands                *speed-up*
  187. =============================
  188.  
  189. In some situations, execution of an external command can be very slow.  This
  190. can also slow down wildcard expansion on Unix.  Here are a few suggestions to
  191. increase the speed.
  192.  
  193. If your .cshrc (or other file, depending on the shell used) is very long, you
  194. should separate it into a section for interactive use and a section for
  195. non-interactive use (often called secondary shells).  When you execute a
  196. command from Vim like ":!ls", you do not need the interactive things (for
  197. example, setting the prompt).  Put the stuff that is not needed after these
  198. lines:
  199.  
  200.     if ($?prompt == 0) then
  201.         exit 0
  202.     endif
  203.  
  204. Another way is to include the "-f" flag in the 'shell' option, e.g.:
  205.  
  206.     :set shell=csh\ -f
  207.  
  208. (the backslash is needed to include the space in the option).
  209. This will make csh completely skip the use of the .cshrc file.  This may cause
  210. some things to stop working though.
  211.  
  212.  
  213. Useful mappings                        *useful-mappings*
  214. ===============
  215.  
  216. Here are a few mappings that some people like to use.
  217.  
  218.     :map ' `
  219. Make the single quote work like a backtick.  Puts the cursor on the column of
  220. a mark, instead of going to the first non-blank character in the line.
  221.  
  222.                             *emacs_keys*
  223. For Emacs-style editing on the command-line:
  224. :cnoremap ^A    <Home>            start of line
  225. :cnoremap ^B    <Left>            back one character
  226. :cnoremap ^D    <Del>            delete character under cursor
  227. :cnoremap ^E    <End>            end of line
  228. :cnoremap ^F    <Right>            forward one character
  229. :cnoremap ^N    <Down>            recall newer command-line
  230. :cnoremap ^P    <Up>            recall previous (older) command-line
  231. :cnoremap <Esc>^B    <S-Left>    back one word
  232. :cnoremap <Esc>^F    <S-Right>    forward one word
  233.  
  234.                             *format_bullet_list*
  235. This mapping will format any bullet list.  It requires that there is an empty
  236. line above and below each list entry:
  237.  
  238.     :map _f   :set ai<CR>{O<Esc>}{)^Wi     <CR>     <Esc>gq}{dd5lDJ
  239.  
  240. (<> notation |<>|.  Note that ^W is "^" "W", not CTRL-W.  You can copy/paste
  241. this into Vim if '<' is not included in 'cpoptions')
  242.  
  243. You also need to set 'textwidth' to a non-zero value, e.g.,
  244.     set tw=70
  245.  
  246. A mapping that does about the same, but takes the indent for the list from the
  247. first line (Note: this mapping is a single long line):
  248.  
  249.     :map _f :set ai<CR>}{a                                                          <Esc>WWmmkD`mi<CR><Esc>kkddpJgq}'mJO<Esc>j
  250.  
  251.  
  252. Compressing the help files                *gzip-helpfile*
  253. ==========================
  254.  
  255. For those of you who are really short on disk space, you can compress the help
  256. files and still be able to view them with Vim.  This makes accessing the help
  257. files a bit slower.
  258.  
  259. (1) Compress all the help files: "gzip doc/*.txt".
  260.  
  261. (2) Edit "doc/vim_tags" and do ":%s=\\.txt<Tab>/=.txt.gz<Tab>/="
  262.     (<> notation |<>|.  You have to type a single backslash for \\ and
  263.     a real Tab for <Tab>)
  264.  
  265. (3) Add these lines to your vimrc:
  266.     set helpfile=<dirname>/vim_help.txt.gz
  267.     autocmd BufReadPre  *.txt.gz set bin
  268.     autocmd BufReadPost *.txt.gz '[,']!gunzip
  269.     autocmd BufReadPost *.txt.gz set nobin
  270.     set cmdheight=2
  271.  
  272. Where <dirname> is the directory where the help files are.  If you have
  273. already included autocommands to edit ".gz" files, you should omit the three
  274. "autocmd" lines.  Setting the command height to two is to avoid having to hit
  275. return; it is not mandatory.
  276.  
  277.  
  278. Executing shell commands in a window            *shell_window*
  279. ====================================
  280.  
  281. There have been questions for the possibility to execute a shell in a window
  282. inside Vim.  The answer: you can't!  Including this would add a lot of code to
  283. Vim, which is a good reason not to do this.  After all, Vim is an editor, it
  284. is not supposed to do non-editing tasks.  However, to get something like this,
  285. you might try splitting your terminal screen or display window with the
  286. "splitvt" program.  You can probably find it on some ftp server.  The person
  287. that knows more about this is Sam Lantinga (slouken@cs.ucdavis.edu).
  288.  
  289.  
  290. Pseudo-Ex mode                        *pseudo-Q*
  291. ==============
  292.  
  293. If you really miss the "Q" command from Vi a lot, you might want to try this
  294. mapping.  It is far from a real Ex mode, but it looks like it.  The "Q"
  295. command can still be used for formatting if you use Visual mode.
  296. You need to type "visual<CR><CR>" to get out of Ex mode.  Unfortunately, any
  297. error message does that too.
  298.  
  299. nnoremap Q :cnoremap <C-V><CR> <C-V><CR>:<CR>:
  300. cabbrev visual cunmap <C-V><CR><NL>
  301.  
  302. (<> notation |<>|.  You should enter this literally.)
  303.  
  304. In a following version of Vim the "Q" command will be made Vi compatible.  Use
  305. "gq" for formatting text.
  306.  
  307.  vim:ts=8:sw=8:js:tw=78:
  308.